//
//  ReportOrderListViewController.swift
//  PropertyCommunity
//
//  Created by benwang on 2021/6/28.
//

import UIKit
import CollectionKit
import JXSegmentedView

class ReportOrderListViewController: UIViewController {

  var collectionView = CollectionView()
  var type: RepairOrderType = .toAudit

    override func viewDidLoad() {
        super.viewDidLoad()

      view.backgroundColor = UIColor(hex: 0xFAFAFA)
      view.addSubview(collectionView)

      collectionView.snp.makeConstraints { maker in
        maker.edges.equalToSuperview()
      }

      let dataSource = ArrayDataSource<RepairOrderModel>(data:[
        RepairOrderModel(),
        RepairOrderModel(),
        RepairOrderModel(),
        RepairOrderModel(),
        RepairOrderModel(),
      ])

      let viewSource = ClosureViewSource<RepairOrderModel, ReportOrderContentView> { model, index in
        return R.nib.reportOrderContentView(owner: self)!
      } viewUpdater: { item, model, index in

      }

      let sizeSource = { (index: Int, data: RepairOrderModel, size: CGSize) in
          return CGSize(width: size.width - 30, height: 150)
      }

      let inset = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)

      let itemProvider = BasicProvider<RepairOrderModel, ReportOrderContentView>(
        dataSource: dataSource,
        viewSource: viewSource,
        sizeSource: sizeSource,
        layout: FlowLayout(spacing: 8, justifyContent: .center)
          .inset(by: inset)
      )

      itemProvider.animator = FadeAnimator()
      itemProvider.tapHandler = { (context) in
        self.jumpToDetail()
      }

      collectionView.provider = ComposedProvider(sections: [itemProvider])
    }

  func jumpToDetail() {
    let vc = RepairOrderDetailViewController()
    vc.type = type
    navigationController?.pushViewController(vc, animated: true)
  }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

extension ReportOrderListViewController: JXSegmentedListContainerViewListDelegate {

  func listView() -> UIView {
    return self.view
  }
}
